Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
@netlify/zip-it-and-ship-it
Advanced tools
@netlify/zip-it-and-ship-it is a Node.js library designed to bundle and package functions for deployment on Netlify. It helps in zipping up serverless functions and their dependencies, making it easier to deploy them to Netlify's platform.
Bundling Functions
This feature allows you to bundle serverless functions from a source directory and output the bundled files to a target directory. The `zipFunctions` method takes two arguments: the source directory and the output directory.
const { zipFunctions } = require('@netlify/zip-it-and-ship-it');
zipFunctions('src/functions', 'out/functions')
.then(results => console.log('Functions bundled:', results))
.catch(error => console.error('Error bundling functions:', error));
Detecting Function Dependencies
This feature helps in detecting the dependencies of the functions in a given directory. The `listFunctions` method takes the source directory as an argument and returns a list of functions along with their dependencies.
const { listFunctions } = require('@netlify/zip-it-and-ship-it');
listFunctions('src/functions')
.then(results => console.log('Function dependencies:', results))
.catch(error => console.error('Error listing functions:', error));
Zipping Individual Functions
This feature allows you to zip an individual function file and output it as a zip file. The `zipFunction` method takes two arguments: the path to the function file and the output path for the zip file.
const { zipFunction } = require('@netlify/zip-it-and-ship-it');
zipFunction('src/functions/myFunction.js', 'out/functions/myFunction.zip')
.then(result => console.log('Function zipped:', result))
.catch(error => console.error('Error zipping function:', error));
The Serverless Framework is a comprehensive toolkit for deploying serverless applications. It supports multiple cloud providers and offers extensive functionality for managing serverless functions, including packaging and deployment. Compared to @netlify/zip-it-and-ship-it, Serverless Framework is more feature-rich and supports a wider range of cloud providers.
Architect (or Arc) is a framework for building and deploying serverless applications. It focuses on simplicity and developer experience, offering tools for defining and deploying serverless functions. While Architect provides similar packaging and deployment capabilities, it is more opinionated and tightly integrated with AWS services compared to @netlify/zip-it-and-ship-it.
Claudia.js is a tool for deploying Node.js projects to AWS Lambda and API Gateway. It simplifies the process of packaging and deploying serverless functions. Claudia.js is more AWS-centric and offers less flexibility in terms of cloud provider support compared to @netlify/zip-it-and-ship-it.
Creates Zip archives from Node.js, Go, and Rust programs. Those archives are ready to be uploaded to AWS Lambda.
This library is used under the hood by several Netlify features, including production CI builds, Netlify CLI and the JavaScript client.
Check Netlify documentation for:
npm install @netlify/zip-it-and-ship-it
srcFolder
: string
destFolder
: string
options
: object?
Return value: Promise<object[]>
const { zipFunctions } = require('@netlify/zip-it-and-ship-it')
const zipNetlifyFunctions = async function () {
const archives = await zipFunctions('functions', 'functions-dist')
return archives
}
Creates Zip archives
from Node.js, Go, and Rust programs. Those archives
are ready to be uploaded to AWS Lambda.
srcFolder
is the source files directory. It must exist. In Netlify, this is the
"Functions folder".
srcFolder
can contain:
index.js
or {dir}.js
where {dir}
is the sub-directory name..js
files (Node.js).zip
archives with Node.js already ready to upload to AWS Lambda.options.zipGo
is true
, those are zipped. Otherwise, those are copied as is.When using Node.js files, only the dependencies required by the main file are bundled, in order to keep the archive as small as possible, which improves the Function runtime performance:
node_modules
) are includedrequire()
'd files are includedrequire()
'd node_modules
are included, recursively@types/*
TypeScript definitionsaws-sdk
*~
, *.swp
, etc. are not includedThis is done by parsing the JavaScript source in each Function file, and reading the package.json
of each Node module.
destFolder
is the directory where each .zip
archive should be output. It is created if it does not exist. In Netlify
CI, this is an unspecified temporary directory inside the CI machine. In Netlify CLI, this is a .netlify/functions
directory in your build directory.
Type: boolean
Default value: false
Whether to zip Go files. If false
, the Go files are copied as is and the filename remains the same.
Type: number
Default value: 5
Maximum number of Functions to bundle at the same time.
Type: number
Default value: zisi
The bundler to use when processing JavaScript functions. Possible values: zisi
, esbuild
, esbuild_zisi
.
When the value is esbuild_zisi
, esbuild
will be used with a fallback to zisi
in case of an error.
Type: array<string>
Default value: []
List of Node modules to include separately inside a node_modules directory.
Applicable only when jsBundler
is esbuild
.
Type: array<string>
Default value: []
List of Node modules to keep out of the bundle.
Applicable only when jsBundler
is esbuild
.
This returns a Promise
resolving to an array of objects describing each archive. Each object has the following
properties.
Type: string
Absolute file path to the archive file.
Type: string
Either "js"
, "go"
, or "rs"
.
srcPath
: string
destFolder
: string
options
: object?
Return value: object | undefined
const { zipFunction } = require('@netlify/zip-it-and-ship-it')
const zipNetlifyFunctions = async function () {
const archive = await zipFunctions('functions/function.js', 'functions-dist')
return archive
}
This is like zipFunctions()
except it bundles a single Function.
The return value is undefined
if the Function is invalid.
srcFolder
: string
Return value: Promise<object[]>
Returns the list of Functions to bundle.
const { listFunctions } = require('@netlify/zip-it-and-ship-it')
const listNetlifyFunctions = async function () {
const functions = await listFunctions('functions/function.js')
return functions
}
Each object has the following properties.
Type: string
Function's name. This is the one used in the Function URL. For example, if a Function is a myFunc.js
regular file, the
name
is myFunc
and the URL is https://{hostname}/.netlify/functions/myFunc
.
Type: string
Absolute path to the Function's main file. If the Function is a Node.js directory, this is its index.js
or {dir}.js
file.
Type: string
Either "js"
, "go"
, or "rs"
.
Type: string
Source file extension. For Node.js, this is either .js
or .zip
. For Go, this can be anything.
srcFolder
: string
Return value: Promise<object[]>
Like listFunctions()
, except it returns not only the Functions main files, but also all
their required files. This is much slower.
const { listFunctionsFiles } = require('@netlify/zip-it-and-ship-it')
const listNetlifyFunctionsFiles = async function () {
const functions = await listFunctionsFiles('functions/function.js')
return functions
}
The return value is the same as listFunctions()
but with the following additional
properties.
Type: string
Absolute file to the source file.
$ zip-it-and-ship-it srcFolder destFolder
The CLI performs the same logic as zipFunctions()
. The archives are
printed on stdout
as a JSON array.
The following options are available:
--zip-go
: see the zipGo
optionzip-it-and-ship-it
does not build, transpile nor install the dependencies of the Functions. This needs to be done
before calling zip-it-and-ship-it
.
If a Node module require()
another Node module but does not list it in its package.json
(dependencies
,
peerDependencies
or optionalDependencies
), it is not bundled, which might make the Function fail.
More information in this issue.
Files required with a require()
statement inside an if
or try
/catch
block are always bundled.
More information in this issue.
Files required with a require()
statement whose argument is not a string literal, e.g. require(variable)
, are never
bundled.
More information in this issue.
If your Function or one of its dependencies uses Node.js native modules, the Node.js version used in AWS Lambda might need to be the same as the one used when installing those native modules.
In Netlify, this is done by ensuring that the following Node.js versions are the same:
10
, but can be
overridden with a .nvmrc
or NODE_VERSION
environment variable.nodejs12.x
but can be
overriden with a AWS_LAMBDA_JS_RUNTIME
environment variable.Note that this problem might not apply for Node.js native modules using the N-API.
More information in this issue.
As of v0.3.0
the serveFunctions
capability has been extracted out to
Netlify Dev.
FAQs
Zip it and ship it
The npm package @netlify/zip-it-and-ship-it receives a total of 149,856 weekly downloads. As such, @netlify/zip-it-and-ship-it popularity was classified as popular.
We found that @netlify/zip-it-and-ship-it demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 16 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.